-
Notifications
You must be signed in to change notification settings - Fork 31
Reduce CppInterOp Emscripten shared library size #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Reduce CppInterOp Emscripten shared library size #655
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #655 +/- ##
=======================================
Coverage 79.18% 79.18%
=======================================
Files 9 9
Lines 3853 3853
=======================================
Hits 3051 3051
Misses 802 802 🚀 New features to boost your workflow:
|
It's a compile time optimization flag I think. Do we need to force it like this everywhere or can we have cmake handle this ? |
It is both a link and compile time optimisation. See https://emscripten.org/docs/tools_reference/emcc.html#emcc-oz . |
ee75d01
to
d9f6630
Compare
Yeah but we still don't want users to look into/pass flags correct during the build correct? We should be able to have cmake handle this. |
I really don't understand the point your trying to make. Using EMCC_CFLAGS in this way to perfectly legitimate way of doing the Emscripten build. Emscripten is designed to be effected by modifying this flag (see https://emscripten.org/docs/tools_reference/emcc.html#environment-variables). If a user changes what we have in the documentation for this flag, and messes something up, then that is on them. I don't understand how putting it in a cmake option changes that. |
My point is simple. We already have compile time and link time flags being passed through cmake, I don't see a need to pass this externally. |
I think what @anutosh491 means is that we need to make this flag as part of our default compiler flags in the CMakeLists.txt. |
@vgvassilev @anutosh491 I first tried locally using |
Putting a note here in case I forget. Using EMCC_CFLAGS="-flto" in the llvm build doesn't end up effecting the shared library size on its own. Used in conjuncation with Oz then the size falls slightly to 45/46 Mb. |
db280e0
to
de7101c
Compare
I have updated this PR to use the flto flag as well, and to compile+link CppInterOp shared library with these flags too. This reduces the shared library size to 44/45 Mb. |
6869da8
to
effdaf8
Compare
@vgvassilev I have now changed this PR to a cmake only solution, instead of using EMCC_CFLAGS. Hopefully that means this PR is ready to go in once the ci passes. Can you review and approve if your happy? The Emscripten cache will need deleting before merging this PR, so that the deployment gets the new smaller library. |
effdaf8
to
ba6ed4c
Compare
The failing job is because I accidentally deleted the wrong cache part way through the ci run. Will rerun tomorrow to show the failed job passing. Noticed that with this change, the Emscripten caches are twice the size they were before, so will need to delete Emscripten llvm 19 jobs for this to go in I think. |
@@ -194,6 +194,9 @@ jobs: | |||
-DLLVM_ENABLE_LIBPFM=OFF \ | |||
-DCLANG_BUILD_TOOLS=OFF \ | |||
-DLLVM_NATIVE_TOOL_DIR=$NATIVE_DIR \ | |||
-DCMAKE_C_FLAGS_RELEASE="-Oz -g0" \ | |||
-DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0" \ | |||
-DLLVM_ENABLE_LTO=Full \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, we necessarily need to change the way llvm is built for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We absolutely need to change the llvm build to get this reduction in size of Emscripten shared library. The majority of the size reduction this PR provides comes from adding these flags to the llvm build.
target_link_options(clangCppInterOp | ||
PRIVATE "SHELL: -s WASM_BIGINT" | ||
PRIVATE "SHELL: -s SIDE_MODULE=1" | ||
PRIVATE "SHELL: ${SYMBOLS_LIST}" | ||
PRIVATE "SHELL: -Oz" | ||
PRIVATE "SHELL: -flto" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm why is lto being involved here ? I've tried using it in the past and I remember it behaves notoriously.
How is it helping us here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding these flags gets us a further reduction in the size of the Emscripten shared library of a few Mb. Needed them for both compile and link flags for it to have any effect. I didn't see any bad side effects your comment suggests (I don't know exactly what you mean by behaves notoriously).
Description
Please include a summary of changes, motivation and context for this PR.
@vgvassilev This change locally reduced the Emscripten shared library size to 47/48 Mb (depends of whether you use dir -lh or du -lh). It still passed all tests and xeus-cpp still could run all the notebook cells it could before (exception throwing is broken in CppInterOps deployment at the moment for some reason). I have cleared the cache of all llvm 20 Emscripten builds for this PR.
Fixes # (issue)
Type of change
Please tick all options which are relevant.
Testing
Please describe the test(s) that you added and ran to verify your changes.
Checklist